#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//int main()
//{
//	int arr[3][4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12} };
//	printf("%d\n",*(arr[0]+1));
//	return 0;
//}
int int_cmp(const void* p1, const void* p2)
{
	return (*(int*)p1 - *(int*)p2);
}

void test()
{
	int arr[] = { 2,8,4,6,3,7,1,5,9 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), int_cmp);

	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}
struct Stu
{
	char name[10];
	int age;
};
int cmp_by_name(const void* p1, const void* p2)
{
	return strcmp(((struct Stu*)p1)->name,((struct Stu*)p2)->name);
}

void test2()
{
	struct Stu s_arr[3] = { {"zhangsan",20},{"lisi",28},{"wangwu",18} };
	qsort(s_arr, 3, sizeof(struct Stu), cmp_by_name);
	printf("\n");
	
}

int cmp_by_age(const void* p1, const void* p2)
{
	return ((struct Stu*)p1)->age - ((struct Stu*)p2)->age;
}

void test3()
{
	struct Stu s_arr[3] = { {"zhangsan",20},{"lisi",28},{"wangwu",18} };
	qsort(s_arr, 3, sizeof(struct Stu), cmp_by_age);

	printf("\n");
	
}
int main()
{
	//test1();

	test2();

	//test3();

	return 0;
}
